<?php
/**
 * Created by PhpStorm.
 * User: sunshine
 * Date: 2016/8/31
 * Time: 8:41
 */
require 'Admin/Model/Model.php';
class J_testModel extends Model
{
    function __Construct()
    {
        parent::__Construct();
        
    }
    function getTestList()
    {
        $sql = "select * from j_test";
        $data = $this->conn->query($sql);
        return $data;
    }
    function addTest($data)
    {
      

        $test = array(
            'pid'=>$data['pid'],
            'content' => trim($data['content']),
            'score'=>$data['score'],
            'ans'=>$data['ans']
          
        );
   
        $keys = implode(',',array_keys($test));
        $values = implode("','", array_values($test));
        $sql="insert into j_test ({$keys}) VALUES ('{$values}')";

        $d = $this->conn->query($sql);
        return $d;
    }
    function getTestByID($id){
        
            $sql = "select * from j_test where j_id=".$id;
            $result = $this->conn->query($sql);
            return $result;
        }
    function update($data)
        {
            $test = array(
                
                'pid' => $data['pid'], 
                'content' => trim($data['content']),
                'score' => $data['score'],
                'ans' => $data['ans']
                );
            
            
            
            $sets = '';
            foreach ($test as $key=>$val)
            {
                $sets.=$key."='".$val."',";
            }
                $sets=rtrim($sets,','); //去掉SQL里的最后一个逗号
                
                $sql="UPDATE j_test SET {$sets} where j_id=".$data['id'];
              
                $result = $this->conn->query($sql);
                return $result;         
            }

            function delete($id)
            {
                $sql = "delete from j_test where j_id=".$id;
                $result = $this->conn->query($sql);
                return $result;
            }




        }
        ?>